﻿@{
    Layout = "~/_SiteLayout.cshtml";
    Page.Title = "Approval Routing";

    bool hasError = false;
    string errorMessage = string.Empty;
    bool hasSuccess = false;
    string successMessage = string.Empty;

    bool isSecretary = KeppelLand.Controllers.B2EController.IsSecretary(KeppelLand.Helpers.UserIdentityHelper.GetSecretaryName());
    string b2e_section = KeppelLand.Controllers.B2EController.GetSection(KeppelLand.Helpers.UserIdentityHelper.GetSecretaryName());

    List<KeppelLand.Entities.ReportingStructure> reportingStructureList = null;
    
    if (isSecretary)
    {
        // Then we get list of people in department
        reportingStructureList = KeppelLand.Controllers.ReportingPeriodController.GetReportingStructureList(b2e_section);
    }

    if (System.Web.HttpContext.Current.User.Identity.Name.Equals("KEPPELLAND\\angpp", StringComparison.InvariantCultureIgnoreCase) ||
        System.Web.HttpContext.Current.User.Identity.Name.Equals("KLL\\angeline.ng", StringComparison.InvariantCultureIgnoreCase) ||
        System.Web.HttpContext.Current.User.Identity.Name.Equals("KEPPELLAND\\Lynette.Hia", StringComparison.InvariantCultureIgnoreCase) ||
        System.Web.HttpContext.Current.User.Identity.Name.Equals("KLL\\Lynette.Hia", StringComparison.InvariantCultureIgnoreCase) ||
        System.Web.HttpContext.Current.User.Identity.Name.Equals("KLL\\zhixian.ong", StringComparison.InvariantCultureIgnoreCase))
    {
        reportingStructureList = KeppelLand.Controllers.ReportingPeriodController.GeAllReportingStructureList();
    }
    
    if (IsPost)
    {

    } // if (IsPost)
}

<div class="container-fluid main-content" role="main">

    @RenderPage("~/Shared/Help_Tab.cshtml")

    @if (hasError)
    {
        <div class="alert alert-danger alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            @Html.Raw(errorMessage)
        </div>
    }
    @if (hasSuccess)
    {
        <div class="alert alert-success alert-dismissible" role="alert">
            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            @successMessage
        </div>
    }

    <h2>
        Edit Approval Routing for @b2e_section
        @if (KeppelLand.Helpers.UserIdentityHelper.IsSimulatingSecretary())
        {
            <text>(simulating @DisplayHelper.LegalName(KeppelLand.Helpers.UserIdentityHelper.GetSecretaryName()))</text>
        }
    </h2>

    @if ((reportingStructureList != null) && (reportingStructureList.Count > 0))
    {
        @*<h2>Employees</h2>*@

        <form method="post" id="approval_form">

            <table class="table table-striped table-bordered" id="pending_action_claim_list">
                <thead>
                    <tr>
                        <th style="white-space:nowrap;" class="col-lg-3">Name</th>
                        <th style="white-space:nowrap;" class="col-lg-3">Recommending</th>
                        <th style="white-space:nowrap;" class="col-lg-3">Approving</th>
                        <th style="white-space:nowrap;" class="col-lg-3">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (KeppelLand.Entities.ReportingStructure reporter in reportingStructureList)
                    {
                    <tr>
                        <td>@DisplayHelper.LegalNameByEmployeeMaster(reporter.EmployeeMaster)</td>
                        <td>@DisplayHelper.LegalNameByEmployeeMaster(reporter.RecommenderId)</td>
                        <td>@DisplayHelper.LegalNameByEmployeeMaster(reporter.ApproverId)</td>
                        <td>
                            <a href="@VirtualPathUtility.ToAbsolute("~/Approval-Routing-Edit.cshtml?id=" + KeppelLand.Helpers.CryptographyHelper.Encrypt(reporter.EmployeeMaster))" class="btn btn-primary btn-sm hidden-print"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span> Edit</a>
                        </td>
                    </tr>
                    }
                </tbody>
            </table>

            <input type="hidden" name="actionButton" id="actionButton" />

        </form>

        <p>&nbsp;</p>
    }
    else
    {
        if (isSecretary)
        {
            <p>No records found.</p>
        }
        else
        {
            <p>This page is accessible only to secretaries.</p>
        }
    }

</div>

@RenderPage("~/Shared/Standard_Modals.cshtml")

<div class="modal fade" id="helpModal" tabindex="-1" role="dialog" aria-labelledby="helpModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="helpModalLabel">Help <small>(Reject Claim)</small></h4>
            </div>
            <div class="modal-body">
                <p>
                    HR users should use this page to reject claim(s).
                </p>

                <div class="panel panel-default">
                    <div class="panel-heading">Instructions</div>
                    <div class="panel-body">
                        <p>
                            This page is for HR users to reject claims that should not be claimable by user.<br />
                        </p>

                        <ul>
                            <li>HR can click on reject button on the corresponding row to reject that claim.</li>
                            <li>If there are too many entries, user can search for the entry based on username and date and then perform the above step.</li>

                            <li>If there are no claims pending submission, page should indicate as such</li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="helpModal_Close" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

@section Scripts
{
    <script type="text/javascript" src="~/Scripts/kendo/2014.3.1119/kendo.ui.core.min.js"></script>
    <script type="text/javascript" src="~/Scripts/moment.js"></script>
    <script type="text/javascript" src="~/Scripts/moment-with-locales.js"></script>
    <script type="text/javascript">
    (function ($) {
        "use strict";
        $(document).ready(function () {
        });
    }(jQuery));

</script>
}